package observer;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 土壤养分传感器
 * 用于监测土壤中的氮、磷、钾等养分含量
 */
public class SoilNutrientSensor {
    private final Map<String, EnvironmentSensor> nutrientSensors;
    private final Random random;

    public SoilNutrientSensor() {
        this.nutrientSensors = new HashMap<>();
        this.random = new Random();

        // 初始化各种养分传感器
        nutrientSensors.put("氮", new EnvironmentSensor("土壤氮含量"));
        nutrientSensors.put("磷", new EnvironmentSensor("土壤磷含量"));
        nutrientSensors.put("钾", new EnvironmentSensor("土壤钾含量"));
    }

    public void addObserver(EnvironmentObserver observer) {
        for (EnvironmentSensor sensor : nutrientSensors.values()) {
            sensor.addObserver(observer);
        }
    }

    public void removeObserver(EnvironmentObserver observer) {
        for (EnvironmentSensor sensor : nutrientSensors.values()) {
            sensor.removeObserver(observer);
        }
    }



    public EnvironmentSensor getSensor(String nutrientType) {
        return nutrientSensors.get(nutrientType);
    }
}
